/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2025/4/26
 * Time: 23:33
 */

#include "ObjectAffiliate.h"
void ObjectAffiliate::SetSize(const glm::vec2 & _size)
{
    size_ = _size;
    SetOffsetByAnchor(anchor_);
}

void ObjectAffiliate::SetScale(float _scale)
{
    size_ *= _scale;
    SetOffsetByAnchor(anchor_);
}

void ObjectAffiliate::SetOffsetByAnchor(Anchor _anchor)
{
    anchor_ = _anchor;
    switch(_anchor) {
        case Anchor::TOP_LEFT:
            offset_ = glm::vec2(0.0f, 0.0f);
            break;
        case Anchor::TOP_CENTER:
            offset_ = glm::vec2(-size_.x / 2.0f, 0);
            break;
        case Anchor::TOP_RIGHT:
            offset_ = glm::vec2(-size_.x, 0.0f);
            break;
        case Anchor::CENTER_LEFT:
            offset_ = glm::vec2(0.0f, -size_.y / 2.0f);
            break;
        case Anchor::CENTER:
            offset_ = glm::vec2(-size_.x / 2.0f, -size_.y / 2.0f);
            break;
        case Anchor::CENTER_RIGHT:
            offset_ = glm::vec2(-size_.x, -size_.y / 2.0f);
            break;
        case Anchor::BOTTOM_LEFT:
            offset_ = glm::vec2(0.0f, -size_.y);
            break;
        case Anchor::BOTTOM_CENTER:
            offset_ = glm::vec2(-size_.x / 2.0f, -size_.y);
            break;
        case Anchor::BOTTOM_RIGHT:
            offset_ = glm::vec2(-size_.x, -size_.y);
            break;
        default:
            break;
    }
}